#include "qopenharmonyplayerservice.h"
#include "qopenharmonyplayercontrol.h"
#include "qopenharmonywindowcontrol.h"


QT_BEGIN_NAMESPACE

QOpenHarmonyPlayerService::QOpenHarmonyPlayerService(QObject *parent)
    : QMediaService(parent)
{
    m_playerControl = new QOpenHarmonyPlayerControl(this);
    m_videoWindowControl = new QOpenHarmonyWindowControl(this);
    m_playerControl->setVideoOutput(m_videoWindowControl);
    m_videoWindowControl->setPlayerControl(m_playerControl);
}

QOpenHarmonyPlayerService::~QOpenHarmonyPlayerService()
{
    delete m_playerControl;
}

QMediaControl *QOpenHarmonyPlayerService::requestControl(const char *name)
{
    if (qstrcmp(name, QMediaPlayerControl_iid) == 0)
        return m_playerControl;
    if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
        return m_videoWindowControl;
    }
    return nullptr;
}

void QOpenHarmonyPlayerService::releaseControl(QMediaControl *control)
{
    if (!control) {
        qWarning("QMediaService::releaseControl():"
                " Attempted release of null control");
    } else if (control == m_videoWindowControl) {
        delete m_videoWindowControl;

        m_videoWindowControl = nullptr;
    }
}

QT_END_NAMESPACE
